<template>
	<BaseContainer>
		<aplid-base-crud ref="crud" class="w-100" v-bind="baseConfig" :operateFormate="onOperateFormate">
			<template v-slot:templateNo="{ row }">
				<span>{{ [row.projectStartDate, row.projectEndDate].join(' 至 ') }}</span>
			</template>
			<template v-slot:organizationSize="{ row }">
				<span>{{ row.organizationSize }}家</span>
			</template>

			<template v-slot:addDialog="{ row, show }">
				<RuleForm v-if="show" :nowRowData="row" @refresh="handleRefresh"></RuleForm>
			</template>
			<template v-slot:editDialog="{ row, show }">
				<RuleForm v-if="show" :nowRowData="row" @refresh="handleRefresh"></RuleForm>
			</template>
			<template v-slot:applyDialog="{ row, show }">
				<ApplyConfig :subsidyApplyConfigId="row.subsidyApplyConfigId" @refresh="handleRefresh" :key="show" :nowRowData="row"> </ApplyConfig>
			</template>
			<template v-slot:approvalDialog="{ row, show }">
				<ApproveConfig @refresh="handleRefresh" v-if="show" :approvalConfigId="row.approvalConfigId" :nowRowData="row"> </ApproveConfig>
			</template>
			<template v-slot:DetailDialog="{ row, show }">
				<DetailConfig  v-if="show" @refresh="handleRefresh" :nowRowData="row"> </DetailConfig>
			</template>
		</aplid-base-crud>

    <AplidDialog v-model="visible" width="65%" :rowData="rowData">
			<DetailConfig  v-if="visible" @refresh="handleRefresh" :nowRowData="rowData"> </DetailConfig>
		</AplidDialog>

	</BaseContainer>
</template>

<script setup lang="ts">
import { ref, nextTick } from 'vue'
import { baseConfig } from './config'
import ApplyConfig from '@/views/instOperate/applyConfig/AddEditForm/index.vue'
import DetailConfig from './components/detailPart/index.vue'
import RuleForm from './components/RuleForm/index.vue'
import AplidDialog from '@/views/instOperate/components/AplidDialog/index.vue'
import ApproveConfig from '@/views/instOperate/auditConfig/AuditForm/index.vue'

const crud: any = ref(null)
const rowData: any = ref({})
const visible = ref(false)
//  处理刷新
const handleRefresh = (query) => {
	nextTick(() => {
		crud.value.refreshChange(query)
	})
}
const handleOperate = (type, row, title) => {
	nextTick(() => {
		crud.value.handleOperate(type, row, title)
	})
}

const onOperateFormate = (data, type) => {
	return new Promise((resolve, reject) => {
		if (type == 'Detail') {
			visible.value = true
			rowData.value = data || {}
		} else {
			resolve(data)
		}
	})
}
</script>
<style scoped lang="scss">
:deep(.el-dialog) {
	--el-dialog-border-radius: 10px;
  --el-dialog-bg-color:rgba(238, 242, 255, 1);
}
:deep(.el-dialog__header) {
	padding: 0;
	margin: 0;
}
:deep(.el-dialog__body) {
  padding: 0;
}
</style>
